﻿fs.util.pageLoadFunction.push(function () {
    var opt = {
        Month: fs.form.month,
        Year: fs.form.year,
        Currency: "RMB",
        WithCurrentMonth: false,
        Type: "",
        Data: "",
        ListTitle: "Flash_HR1",
        CompanyCode: fs.form.companycode,
        ActionType: "Calc"
    };
    refrenceData.receive(opt, function (data) {
        window.CM_HR01060100 = JSON.parse(data.Data).CM_HR01060100;
        window.CM_HR01060101 = JSON.parse(data.Data).CM_HR01060101;
        window.CM_HR01060102 = JSON.parse(data.Data).CM_HR01060102;
        window.CM_HR01010100 = JSON.parse(data.Data).CM_HR01010100;
        // callback();
    }, "&fields=CM_HR01060100,CM_HR01060101,CM_HR01060102,CM_HR01010100");


    firstColumns = [
        { index: 0, headerText: "YTD M-1", edit: true, style: 'gray', hide: true, width: 80, rowText: "YTDM_1" },
        { index: 0, headerText: "Last Month", edit: true, style: 'gray', reference: true, readonly: true, width: 80, rowText: "LM" },
        { index: 2, headerText: "YTD", currentrow: true, edit: true, style: 'blue', readonly: true, width: 80, rowText: "YTD" },
        { index: 1, headerText: "Current Month", edit: true, style: '', width: 80, rowText: "CM" }
    ];
});
var headCountAfterBinding = function () {
    var self = this;

    self["YTD"] = ko.computed(function () {
        return parseFloat(unWarpValue(self['CM'])).toFix(self.digits);
    })
}

var readyJSON = [
{ accountcode: "HR01010100", unit: "number", rowAfterBinding: headCountAfterBinding, description: "Roquette Headcount-month end", datarow: true, bold: true, index: 0, Process: [{
    Field: "All",
    Exp: {
        mode: "to",
        start: "HR01010111",
        end: "HR01010123",
        equ: "+"
    }
}], ProcessTODO: "=∑"
},
{ accountcode: "HR01010111", unit: "number", rowAfterBinding: headCountAfterBinding, description: "Sales and Marketing", datarow: true },
{ accountcode: "HR01010112", unit: "number", rowAfterBinding: headCountAfterBinding, description: "R&D", datarow: true },
{ accountcode: "HR01010113", unit: "number", rowAfterBinding: headCountAfterBinding, description: "Procurement", datarow: true },
{ accountcode: "HR01010114", unit: "number", rowAfterBinding: headCountAfterBinding, description: "Logistic", datarow: true },
{ accountcode: "HR01010115", unit: "number", rowAfterBinding: headCountAfterBinding, description: "Supply chain", datarow: true },
{ accountcode: "HR01010116", unit: "number", rowAfterBinding: headCountAfterBinding, description: "Manufacturing", datarow: true },
{ accountcode: "HR01010117", unit: "number", rowAfterBinding: headCountAfterBinding, description: "Finance", datarow: true },
{ accountcode: "HR01010118", unit: "number", rowAfterBinding: headCountAfterBinding, description: "IT ", datarow: true },
{ accountcode: "HR01010119", unit: "number", rowAfterBinding: headCountAfterBinding, description: "HR", datarow: true },
{ accountcode: "HR01010120", unit: "number", rowAfterBinding: headCountAfterBinding, description: "General Affairs", datarow: true },
{ accountcode: "HR01010121", unit: "number", rowAfterBinding: headCountAfterBinding, description: "Legal", datarow: true },
{ accountcode: "HR01010122", unit: "number", rowAfterBinding: headCountAfterBinding, description: "Top management", datarow: true },
{ accountcode: "HR01010123", unit: "number", rowAfterBinding: headCountAfterBinding, description: "Other functions / Miscellaneous ", datarow: true },

{ emptyrow: true, description: "" },
{ accountcode: "HR01010200", rowAfterBinding: headCountAfterBinding, description: "Temp Headcount-month end", datarow: true, bold: true, unit: "number" },
{ emptyrow: true, description: "" },
{ accountcode: "HR01010301", rowAfterBinding: headCountAfterBinding, description: "Direct", datarow: true, bold: true, unit: "number" },
{ emptyrow: true, description: "" },
{ accountcode: "HR01010302", rowAfterBinding: headCountAfterBinding, description: "Indirect", datarow: true, bold: true, unit: "number" },
{ accountcode: "Control", description: "HR01010100 = HR01010301+HR01010302",index:10, controlrow: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["HR01010100", "HR01010301", "HR01010302"],
        equ: ["-(", "+", ")-"]
    }
}]
},
{ emptyrow: true, description: "" },
{ accountcode: "HR01020100", unit: "number", digits: 1, description: "Roquette Full Time Equivalent-month", withYTD: true, datarow: true, bold: true, index: 1, Process: [{
    Field: "All",
    Exp: {
        mode: "to",
        start: "HR01020111",
        end: "HR01020123",
        equ: "+"
    }
}], ProcessTODO: "=∑"
},
{ accountcode: "HR01020111", unit: "number", digits: 1, description: "Sales and Marketing", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010111", "CM|HR01010111"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010111", "CM|HR01010111"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020112", unit: "number", digits: 1, description: "R&D", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010112", "CM|HR01010112"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010112", "CM|HR01010112"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020113", unit: "number", digits: 1, description: "Procurement", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010113", "CM|HR01010113"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010113", "CM|HR01010113"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020114", unit: "number", digits: 1, description: "Logistic", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010114", "CM|HR01010114"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010114", "CM|HR01010114"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020115", unit: "number", digits: 1, description: "Supply chain", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010115", "CM|HR01010115"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010115", "CM|HR01010115"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020116", unit: "number", digits: 1, description: "Manufacturing", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010116", "CM|HR01010116"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010116", "CM|HR01010116"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020117", unit: "number", digits: 1, description: "Finance", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010117", "CM|HR01010117"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010117", "CM|HR01010117"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020118", unit: "number", digits: 1, description: "IT ", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010118", "CM|HR01010118"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010118", "CM|HR01010118"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020119", unit: "number", digits: 1, description: "HR", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010119", "CM|HR01010119"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010119", "CM|HR01010119"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020120", unit: "number", digits: 1, description: "General Affairs", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010120", "CM|HR01010120"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010120", "CM|HR01010120"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020121", unit: "number", digits: 1, description: "Legal", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010121", "CM|HR01010121"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010121", "CM|HR01010121"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020122", unit: "number", digits: 1, description: "Top management", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010122", "CM|HR01010122"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010122", "CM|HR01010122"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ accountcode: "HR01020123", unit: "number", digits: 1, description: "Other functions / Miscellaneous ", datarow: true, withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["LM|HR01010123", "CM|HR01010123"],
        equ: " (function(){if(_M_>1){return (({0})+({1}))/2;}else{return ({1});}})() ", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["YTDM_1|HR01010123", "CM|HR01010123"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ emptyrow: true, description: "" },
{ accountcode: "HR01020200",CMstyle:"none", description: "Temp Full Time Equivalent-month", digits: 1, datarow: true, bold: true,manual:true, unit: "number", withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        skip: true,
        manual:true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["CM|HR01020200", "YTDM_1|HR01020200"],
        equ: "(({0})+({1}))/_M_", equexpression: true
    }
}]
},
{ emptyrow: true, description: "" },
{ accountcode: "HR01020300", description: "Working Days", datarow: true, bold: true, unit: "Day" },
{ emptyrow: true, description: "" },
{ accountcode: "HR01030101", description: "Roquette-Working hours-Excl. OT", index:1, datarow: true, unit: "hour", Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["HR01020100", "HR01020300"],
        equ: "({0})*({1})*8", equexpression: true
    }
}]
},
{ accountcode: "HR01030102", description: "Temp-Working hours-Excl. OT", datarow: true, unit: "hour" },
{ accountcode: "HR01030100", description: "Total-working hour-Excl. OT", index: 2, datarow: true, bold: true, unit: "hour", Process: [{
    Field: "All",
    Exp: {
        mode: "search",
        fields: ["HR01030101", "HR01030102"],
        equ: "+"
    }
}]
},
{ emptyrow: true, description: "" },
{ accountcode: "HR01040101", description: "Roquette-Overtime hours", datarow: true, unit: "hour" },
{ accountcode: "HR01040102", description: "Temp-Overtime hours", datarow: true, unit: "hour" },
{ accountcode: "HR01040100", description: "Total -Overtime hours", datarow: true, bold: true, unit: "hour", Process: [{
    Field: "All",
    Exp: {
        mode: "search",
        fields: ["HR01040101", "HR01040102"],
        equ: "+"
    }
}]
},
{ emptyrow: true, description: "" },
{ accountcode: "HR01050100", description: "Total working hours", index: 3, datarow: true, unit: "hour", Process: [{
    Field: "All",
    Exp: {
        mode: "search",
        fields: ["HR01030100", "HR01040100"],
        equ: "+"
    }
}]
},
{ emptyrow: true, description: "" },
{ accountcode: "HR01060100", description: "Headcount-Turnover", datarow: true, bold: true, unit: "number", Process: [{
    Field: "All",
    Exp: {
        mode: "search",
        fields: ["HR01060101", "HR01060102"],
        equ: "+"
    }
}]
},
{ accountcode: "HR01060101", description: "voluntary", datarow: true, unit: "number" },
{ accountcode: "HR01060102", description: "Involuntary", datarow: true, unit: "number" },
{ emptyrow: true, description: "" },
{ accountcode: "HR01070100", description: "Turnover Ratio(Month/12MR)", index: 2, digits: 1, datarow: true, unit: "%", withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["HR01060100", "HR01020100"],
        equ: "({0})/({1})*100", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["CM|HR01060100", "CM|HR01010100"],
        equ: "(({0})+parseFloat(fs.util.strFilter(CM_HR01060100)))/((({1})+parseFloat(fs.util.strFilter(CM_HR01010100)))/12)*100", equexpression: true
    }
}]
},
{ accountcode: "HR01070101", description: "Voluntary ratio(Month/12MR)", index: 2, digits: 1, datarow: true, unit: "%", withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["HR01060101", "HR01020100"],
        equ: "({0})/({1})*100", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["CM|HR01060101", "CM|HR01010100"],
        equ: "(({0})+parseFloat(fs.util.strFilter(CM_HR01060101)))/((({1})+parseFloat(fs.util.strFilter(CM_HR01010100)))/12)*100", equexpression: true
    }
}]
},
{ accountcode: "HR01070102", description: "Involuntary ratio(Month/12MR)", index: 2, digits: 1, datarow: true, unit: "%", withYTD: true, Process: [{
    Field: "CM",
    Exp: {
        mode: "search",
        fields: ["HR01060102", "HR01020100"],
        equ: "({0})/({1})*100", equexpression: true
    }
}, {
    Field: "YTD",
    Exp: {
        mode: "search",
        fields: ["CM|HR01060102", "CM|HR01010100"],
        equ: "(({0})+parseFloat(fs.util.strFilter(CM_HR01060102)))/((({1})+parseFloat(fs.util.strFilter(CM_HR01010100)))/12)*100", equexpression: true
    }
}]
},
{ emptyrow: true, description: "" },
{ accountcode: "HR01080100", description: "Training hours", datarow: true, unit: "Number" },
{ accountcode: "HR01090100", description: "Number of promotion", datarow: true, unit: "Number" }
];
